package com.avocado.bt.impl.composite;

import com.avocado.bt.BTState;
import com.avocado.bt.IBTContext;
import com.avocado.bt.IBTNode;
import com.avocado.bt.abs.composite.CompositeNode;

/**
 * 依次执行所有节点直到其中一个失败或者全部成功位置
 *
 * @Author: zsh
 * @Date: 2023/10/16 17:14
 */
public class SequenceNode extends CompositeNode {

    public SequenceNode(String param) {
        super(param);
    }

    @Override
    public BTState doUpdate(IBTContext context) {
        for (IBTNode childNode : getChildNodes()) {
            BTState tick = childNode.tick();
            if (BTState.Failure.equals(tick)) {
                return BTState.Failure;
            }
        }
        return BTState.Completed;
    }

}
